home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fileli1a / filefunc.bas < prev    next >
BASIC Source File  |  1999-10-04  |  3KB  |  119 lines

  1. Attribute VB_Name = "FileFunc"
  2. Option Explicit
  3.  
  4. Function FileExists(ByVal FileName As String) As Integer
  5. Dim Temp$, MB_OK
  6.  
  7.     'Set Default
  8.     FileExists = True
  9.     
  10.     'Set up error handler
  11. On Error Resume Next
  12.  
  13.     'Attempt to grab date and time
  14.     Temp$ = FileDateTime(FileName)
  15.  
  16.     'Process errors
  17.     Select Case Err
  18.         Case 53, 76, 68   'File Does Not Exist
  19.             FileExists = False
  20.             Err = 0
  21.         Case Else
  22.             If Err <> 0 Then
  23.                 MsgBox "Error Number: " & Err & Chr$(10) & Chr$(13) & " " & Error, MB_OK, "Error"
  24.                 End
  25.             End If
  26.     End Select
  27. End Function
  28.  
  29. Function AddPathToFile(ByVal sPathIn As String, ByVal sFileNameIn As String) As String
  30. '*******************************************************************
  31. '
  32. '  PURPOSE: Takes a path (including Drive letter and any subdirs) and
  33. '           concatenates the file name to path. Path may be empty, path
  34. '           may or may not have an ending backslash '\'.  No validation
  35. '           or existance is check on path or file.
  36. '
  37. '  INPUTS:  sPathIn - Path to use
  38. '           sFileNameIn - Filename to use
  39. '
  40. '
  41. '  OUTPUTS:  N/A
  42. '
  43. '  RETURNS:  Path concatenated to File.
  44. '
  45. '*******************************************************************
  46. Dim sPath As String
  47. Dim sFileName As String
  48.  
  49.  
  50.     'Remove any leading or trailing spaces
  51.     sPath = Trim$(sPathIn)
  52.     sFileName = Trim$(sFileNameIn)
  53.  
  54.     If sPath = "" Then
  55.        AddPathToFile = sFileName
  56.     Else
  57.        If Right$(sPath, 1) = "\" Then
  58.          AddPathToFile = sPath & sFileName
  59.        Else
  60.          AddPathToFile = sPath & "\" & sFileName
  61.        End If
  62.     End If
  63.  
  64. End Function
  65. Function ExtractFileName(sFileName As Variant) As String
  66. '*******************************************************************
  67. '
  68. '  PURPOSE: This returns just a file name from a full/partial path.
  69. '
  70. '  INPUTS:  sFileName - String Data to remove path from.
  71. '
  72. '  OUTPUTS: N/A
  73. '
  74. '  RETURNS: This function returns all the characters from right to the
  75. '           first \.  Does NOT check validity of the filename....
  76. '
  77. '*******************************************************************
  78. Dim nIdx As Integer
  79.  
  80.  
  81.     For nIdx = Len(sFileName) To 1 Step -1
  82.         If Mid$(sFileName, nIdx, 1) = "\" Then
  83.             ExtractFileName = Mid$(sFileName, nIdx + 1)
  84.             Exit Function
  85.         End If
  86.     Next nIdx
  87.  
  88.     ExtractFileName = sFileName
  89.  
  90. End Function
  91.  
  92. Function ExtractPath(sFileName) As String
  93. '*******************************************************************
  94. '
  95. '  PURPOSE: This returns just a path name from a full/partial path.
  96. '
  97. '  INPUTS:  sFileName - String Data to remove file from.
  98. '
  99. '  OUTPUTS: N/A
  100. '
  101. '  RETURNS: This function returns all the characters from left to the last
  102. '           first \.  Does NOT check validity of the filename/Path....
  103. '*******************************************************************
  104. Dim nIdx As Integer
  105.  
  106.  
  107.     For nIdx = Len(sFileName) To 1 Step -1
  108.        If Mid$(sFileName, nIdx, 1) = "\" Then
  109.           ExtractPath = Mid$(sFileName, 1, nIdx)
  110.           Exit Function
  111.        End If
  112.     Next nIdx
  113.     
  114.     ExtractPath = sFileName
  115.  
  116. End Function
  117.  
  118.  
  119.